import numpy as np
import matplotlib.pyplot as plt

# 设置图像大小
height, width = 480, 480

# 1. 生成黑白像素点图像
num_points_bw = height*width  # 黑白像素点的数量
x_bw = np.random.randint(0, width, num_points_bw)
y_bw = np.random.randint(0, height, num_points_bw)
image_bw = np.zeros((height, width), dtype=np.uint8)
image_bw[y_bw, x_bw] = 255

# 2. 生成彩色像素点图像
num_points_color = height*width  # 彩色像素点的数量
x_color = np.random.randint(0, width, num_points_color)
y_color = np.random.randint(0, height, num_points_color)
image_color = np.zeros((height, width, 3), dtype=np.uint8)
colors = np.random.randint(0, 256, size=(num_points_color, 3))
image_color[y_color, x_color] = colors

# 3. 生成10x10彩色像素方块图像
num_blocks = 100  # 彩色方块的数量
block_size = (height//10)  # 方块大小
image_blocks = np.zeros((height, width, 3), dtype=np.uint8)
# 生成10x10彩色像素方块图像，均匀分布
for i in range(block_size):
    for j in range(block_size):
        # 计算方块的起始坐标
        x_start = j * block_size
        y_start = i * block_size
        # 为每个方块生成随机颜色
        block_color = np.random.randint(0, 256, size=(3,))
        # 填充方块
        image_blocks[y_start:y_start+block_size, x_start:x_start+block_size] = block_color

# 显示图像
fig, axs = plt.subplots(1, 3, figsize=(15, 5))
axs[0].imshow(image_bw, cmap='gray')
axs[0].set_title('Black and White Pixel Points')
axs[0].axis('off')

axs[1].imshow(image_color)
axs[1].set_title('Colored Pixel Points')
axs[1].axis('off')

axs[2].imshow(image_blocks)
axs[2].set_title('10x10 Colored Blocks')
axs[2].axis('off')

plt.show()
